package db

import (
	"goDemo/entity"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

type Member struct {
	// gorm.Model
	Id                 int
	Name               string `gorm:"column:name"`
	DatachangeLasttime string
}
var db *gorm.DB

func init()  {
	db,_ = gorm.Open(mysql.Open("test:123pop@(taofoo.top:3306)/test?charset=utf8&parseTime=True&loc=Local"))
}

func Get(pageNum,pageSize int)(interface{},interface{}) {


	var ux []map[string]interface{}
	infoDb := db.Debug().Table("member_info")

	var count int64
	infoDb.Count(&count)

	infoDb.Limit(pageSize).Offset((pageNum-1)*pageSize)
	infoDb.Find(&ux)

	return ux,count
}

func Add(user entity.User) interface{} {
	create := db.Debug().Model(&entity.User{}).Table("member_info").Create(&user)
	if create.Error == nil {
		return user
	}
	return nil
}

func Conn() interface{} {
	//db.Order()
	return "ok"
}